(function(){
try{document.body.removeChild(document.getElementById('cheatsheetArea'));}catch(e){}
var lng = ['ja','en'];
var keys = ["define:","cache:","link:","related:","info:","site:","allintitle:","intitle:","allinurl:"
,"inurl:"," * ","safesearch:"," OR ","filetype:","allintext:","intext:"];
var messageObj = {
	"define:":
		{"ja":"phrase の定義を調べる"
		,"en":"Show a list of definitions for phrase"}
		
	,"cache:":
		{"ja":"example.comのキャッシュから検索"
		,"en":"Google's cache of example.com"}
		
	,"link:":
		{"ja":"example.comにリンクしているページを検索"
		,"en":"List of websites that link to example.com"}
		
	,"related:":
		{"ja":"example.comに類似したページを検索"
		,"en":"List webpages similar to example.com"}
		
	,"info:":
		{"ja":"example.comに関する提供可能な情報を表示"
		,"en":"Show information that Google has about example.com"}
		
	,"site:":
		{"ja":"example.com内を検索"
		,"en":"List all webpages hosted at example.com"}
		
	,"allintitle:":
		{"ja":"タイトルとqueryが一致するページを検索"
		,"en":"Restrict the results to those with all of the query words in the title."}
		
	,"intitle:":
		{"ja":"タイトルにqueryが含まれるページを検索"
		,"en":"Restrict the results to documents containing that word in the title."}
		
	,"allinurl:":
		{"ja":"urlとqueryが一致するページを検索"
		,"en":"Restrict the results to those with all of the query words in the URL"}
		
	,"inurl:":
		{"ja":"urlにqueryが含まれるページを検索"
		,"en":"Restrict the results to documents containing that words in the URL"}
		
	," * ":
		{"ja":"phrase1とphrase2の間に1文字以上含まれる"
		,"en":"the words phrase1 and phrase2 separated by exactly one word"}
		
	,"safesearch:":
		{"ja":"アダルトコンテンツを避けて検索"
		,"en":"Search for sex education material without returning adult sites."}
		
	," OR ":
		{"ja":"phrase1もしくはphrase2を含むページを検索"
		,"en":"either the word phrase1 or the word phase2"}
		
	,"filetype:":
		{"ja":"ファイル形式を指定して検索"
		,"en":"Restrict the results by the file type."}
		
	,"allintext:":
		{"ja":"本文にqueryがすべて含まれるページを検索"
		,"en":"Restrict the results to those with all of the query words in the contents"}
		
	,"intext:":
		{"ja":"本文にqueryが含まれているページを検索"
		,"en":"Restrict the results to documents containing that word in the contents"}
};
var exampleObj = {
	"define:"		:"<b>define:</b><I>phrase</I>"
	,"cache:"		:"<b>cache:</b><I>www.example.com</I>"
	,"link:"		:"<b>link:</b><I>www.example.com</I>"
	,"related:"		:"<b>related:</b><I>www.example.com</I>"
	,"info:"		:"<b>info:</b><I>www.example.com</I>"
	,"site:"		:"<b>site:</b><I>www.example.com</I>"
	,"allintitle:"	:"<b>allintitle:</b><I>query</I>"
	,"intitle:"		:"<b>intitle:</b><I>query</I>"
	,"allinurl:"	:"<b>allinurl:</b><I>query</I>"
	,"inurl:"		:"<b>inurl:</b><I>query</I>"
	," * "			:"<I>phrase1</I><b> * </b><I>phrase2</I>"
	,"safesearch:"	:"<b>safesearch:</b><I>query</I>"
	," AND "		:"<I>phrase1</I><b> AND </b><I>phrase2</I>"
	," OR "			:"<I>phrase1</I><b> OR </b><I>phrase2</I>"
	,"filetype:"	:"<b>filetype:</b><I>query</I>"
	,"allinanchor:"	:"<b>allinanchor:</b><I>query</I>"
	,"inanchor:"	:"<b>inanchor:</b><I>query</I>"
	,"allintext:"	:"<b>allintext:</b><I>query</I>"
	,"intext:"		:"<b>intext:</b><I>query</I>"
};
var setValue = function(word){
	try{
		var f;
		try{
			f = document.f.q;
		}catch(e){
			f = document.gs.q;
		}
		f.value = f.value + ' ' + this.key;
		f.focus();
	}catch(e){}
	document.body.removeChild(document.getElementById('cheatsheetArea'));
};

var scripts = document.getElementsByTagName('script');
var lng = 'en';
for(var i = 0,len=scripts.length;i<len;i++){
	if(scripts[i].src.indexOf('cs_google_search.js') > 0){
		try{
			lng = scripts[i].src.split('?')[1].split('&')[0].split('=')[1];
		}catch(e){}
	}
}

var cheattxt = '<p style="margin:0px;width:100%;background-color:#EEEEEE">[<a id="cheatsheettoggle" href="javascript:void(0);">-</a>] <B>Google Cheat Sheet</B><a href="javascript:void(0);" onclick="document.body.removeChild(document.getElementById(\'cheatsheetArea\'));" style="position:absolute;right:3px">[close]</a><p>'
+'<div id="cheatsheetbody" style="padding:0px;margin:0px;display:block;">'
+'</div>';

var d = document.createElement('div');
d.id='cheatsheetArea'
d.style.position = 'absolute';
d.style.padding = '5px'
d.style.top = '20px';
d.style.right = '15px';
d.style.width = '330px';
d.style.backgroundColor = '#FFFFFF';
d.style.border = '1px solid #999999';
d.style.fontSize = '10pt';
d.style.zIndex = '100000';
d.style.textAlign = 'left';
d.innerHTML = cheattxt;
document.body.appendChild(d);
for(var i = 0,len = keys.length;i<len;i++){
	var appender = document.getElementById('cheatsheetbody');
	var key = keys[i];
	var dt = document.createElement('dt');
	dt.innerHTML = exampleObj[key];
	dt.key = key;
	dt.onclick = function(){
		setValue.apply(this);
	};
	dt.style.borderTop = '1px solid #AAAAAA';
	dt.style.cursor = 'hand';
	appender.appendChild(dt);

	var dd = document.createElement('dd');
	dd.innerHTML = messageObj[key][lng];
	dd.key = key;
	dd.onclick = function(){
		setValue.apply(this);
	};
	dd.style.color = '#666666';
	dd.style.cursor = 'hand';
	appender.appendChild(dd);

}

var a = document.getElementById('cheatsheettoggle');
a.onclick = function(){
	var b = document.getElementById('cheatsheetbody');
	if(b.style.display == 'none'){
		b.style.display = 'block';
		a.innerHTML = '-';
	}else{
		b.style.display = 'none';
		a.innerHTML = '+';
	}
}
})();
